import Vue from 'vue'
import Router from 'vue-router'
import Login from '../pages/Login'
import Layout from '../pages/Layout'
//菜单管理
import Menu from '../pages/menu/Index'
import MenuAdd from '../pages/menu/Add'
import MenuEdit from '../pages/menu/Edit'
//角色管理
import Role from '../pages/role/Index'
import RoleAdd from '../pages/role/Add'
import RoleEdit from '../pages/menu/Edit'
//管理员管理
import Admin from '../pages/admin/Index'
import AdminAdd from '../pages/admin/Add'
import AdminEdit from '../pages/admin/Edit'
//分类管理
import Cate from '../pages/category/Index'
import CateAdd from '../pages/category/Add'
import CateEdit from '../pages/category/Edit'
//// 规格管理
import Specs from '../pages/specs/Index'
import SpecsAdd from '../pages/specs/Add'
import SpecsEdit from '../pages/specs/Edit'
import Wangeditor from '../pages/Wangeditor'
// 商品管理
import Goods from '../pages/goods/Index'
import GoodsAdd from '../pages/goods/Add'
import GoodsEdit from '../pages/goods/Edit'
// 数据统计
import Bar from '../pages/charts/Bar'
import Pie from '../pages/charts/Pie'


// import { component } from 'vue/types/umd'
// import Cate from '../pages/category/Index'




Vue.use(Router)

const routes = [{
    path: '/',
    component: Layout,
    redirect:'/wangeditor',
    children:[
      {
        path:'/wangeditor',
        component:Wangeditor

      },
      {
        path:'/menu',
        component:Menu
      },
      {
        path:"/menu/add",
        component:MenuAdd

      },
      {
        path:'/menu/:id',
        component:MenuEdit

      },
      {
        path:'/role',
        component:Role

      },
      {
        path:'/role/add',
        component:RoleAdd


      },
      {
        path:'/role/:id',
        component:RoleEdit

      },
      {
        path:'/admin',
        component:Admin
    
      },
      {
        path:'/admin/add',
        component:AdminAdd


      },
      {
        path:'/admin/:uid',
        component:AdminEdit,
        props:true
        

      },
      {
        path:'/category',
        component:Cate,
        props:true
      },
      {
        path:'/category/add',
        component:CateAdd
      },
      {
        path:'/category/:id',
        component:CateEdit


      },
      {
        path:'/specs',
        component:Specs
      },
      {
        path:'/specs/add',
        component:SpecsAdd
      },
      {
        path:'/specs/:id',
        component:SpecsEdit
      },
      {
        path:'goods',
        component:Goods


      },
      {
        path:"goods/add",
        component:GoodsAdd


      },  
      {
        path:'/goods/:id',
        component:GoodsEdit  
      },
      {
        path: '/bar',
        component: Bar,
        meta: {
          title: '销售业绩柱状图'
        }
      },
      {
        path: '/pie',
        component: Pie,
        meta: {
          title: '销售业绩饼状图'
        }
      },
      
     
    
      
     
      
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
]

const router = new Router({
  routes
})
router.beforeEach(function(to,from,next){
  if(to.path!=='/login'){
    const userInfo=sessionStorage.getItem('userinfo')
    if(!userInfo){
      return next('/login')
    }
  }
  next()

})

export default router
